/**
 * 
 */
package ma.moliere.transverse;

import java.io.Serializable;

import javax.faces.context.FacesContext;
import javax.faces.event.PhaseEvent;
import javax.faces.event.PhaseId;
import javax.faces.event.PhaseListener;

import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;

/**
 * @author sasmami
 * 
 */
public class LoginErrorPhaseListener implements PhaseListener, Serializable {

	/**
	 * Serial version id.
	 */
	private static final long serialVersionUID = -5196122515158321890L;

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void afterPhase(final PhaseEvent event) {
		// TODO Auto-generated method stub

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see javax.faces.event.PhaseListener#beforePhase(javax.faces.event.PhaseEvent)
	 */
	@Override
	public void beforePhase(final PhaseEvent event) {
		Exception e = (Exception) FacesContext.getCurrentInstance().getExternalContext().getSessionMap()
			.get(UsernamePasswordAuthenticationFilter.SPRING_SECURITY_FORM_PASSWORD_KEY);

		// if (e instanceof BadCredentialsException) {
		// FacesContext.getCurrentInstance().getExternalContext().getSessionMap()
		// .put(AbstractProcessingFilter.SPRING_SECURITY_LAST_EXCEPTION_KEY, null);
		//
		// FacesUtils.addErrorMessage("Username or password not valid.");
		// }
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see javax.faces.event.PhaseListener#getPhaseId()
	 */
	@Override
	public PhaseId getPhaseId() {
		// TODO Auto-generated method stub
		return null;
	}

}
